const ResultVo = require('../utils/ResultVo')
const Exception = require('../exception/Exception')
const ExceptionHandler = (err, req, res, next) => {
  if(err.name === 'UnauthorizedError') {
    res.status(401).json(ResultVo.failNull(err.code, err.message))
  } else if(err instanceof Exception) {
    res.status(400).json(ResultVo.fail(err.code, err.message, err.error))
  } else {
    res.status(500).json(ResultVo.failNull(500, err.message))
  }
}

module.exports = ExceptionHandler